const MIN_DISTANCE = 10;
export function getDirection(x: number, y: number) {
  if (x > y && x > MIN_DISTANCE) {
    return "horizontal";
  }
  if (y > x && y > MIN_DISTANCE) {
    return "vertical";
  }
  return "";
}
export function stopPropagation(event: Event) {
  event.stopPropagation();
}
export function preventDefault(event: Event, isStopPropagation = true) {
  /* istanbul ignore else */
  if (typeof event.cancelable !== "boolean" || event.cancelable) {
    event.preventDefault();
  }

  if (isStopPropagation) {
    stopPropagation(event);
  }
}

export function getRealStyle(el: HTMLElement, styles = ["width", "height"]) {
  const computedStyle: any = (window as any).getComputedStyle(el);
  const res: any = {};
  const numberStyles = ["width", "height"];
  styles.forEach((style: string) => {
    if (numberStyles.indexOf(style) != -1) {
      res[style] = Number(computedStyle[style].replace("px", ""));
    } else {
      res[style] = computedStyle[style];
    }
  });
  return styles.length > 0 ? res : computedStyle;
}
